<?php
$total_image_count = count($arrImages);
$image_number = 1;
//$placeholder = file_create_url(variable_get('jail_place', drupal_get_path('module', 'jail') . '/white.gif'));

$placeholder = base_path() . drupal_get_path("module","section_blocks") . '/trending/ajax-loader.gif';
?>

<div class="gallery-category-rotater clearfix">
  <div id="home-loading-wrapper">
  <?php print _loader_image_html(); ?>
  </div>
  <div class="loading-content" style="display: none;"> 
    <div id="gallery-content-container" class="gallery-container-div clearfix">
      <div id="jcarousel-list">
	<div id="gallery-carousel">
          <?php foreach ($arrImages as $key=>$value): ?>
          <?php
             //get the image description
             if ( (isset($value['field_description']['und'])) && (($value['field_description']['und'][0]['value']) != "") ){
             $image_description = $value['field_description']['und'][0]['value']; 
             }
             else {
             $image_description = $value['title']; 
             }
             //get the original image path for fancybox
             $gallery_image_path = file_create_url($value['uri']);
             ?>
          <div class="main-image-wrapper">
            <div id="main-image-<?php print $key; ?>" class="main-images">
              <!-- a tag for fanycbox, rel for grouping images and title for caption-->
							<!-- strip tags from a tag title as it breaks slider if description has html  -->
              <a title="<?php print strip_tags($image_description); ?>" class="gallery-slider-image" href="<?php print $gallery_image_path; ?>" rel="galleryslider" >
		<?php 
                   // Assign emtpy just in case.
                   $image_alt = '';
                   $image_title = '';

                   if (!empty($value['alt'])) {
                   $image_alt = $value['alt'];
                   }
                   if (!empty($value['title'])) {
                   $image_title = $value['title'];
                   }

//drupal_set_message('values = <pre>'. print_r($value, true).'</pre>', 'status', TRUE); 

$attributes = array();
$attributes['alt'] = $image_alt;
$attributes['title'] = $image_title;
if ($image_number < 3) {
  $attributes['src'] = image_style_url($main_slide, $value['uri']);
  $gallery_image_id = 'dc-gallery-' . $key;
	$gallery_image_class = '';
	print '<img id="' . $gallery_image_id . '" class="' . $gallery_image_class .  '"' . drupal_attributes($attributes) . ' />';
}
else {
  $attributes['src'] = $placeholder;
  $attributes['data-href'] = image_style_url($main_slide, $value['uri']);
  $gallery_image_class = 'gallery-main-image';
  $gallery_image_id = 'dc-gallery-' . $key;
	print '<img class="placeholder-image" src="' . $placeholder .  '"/>';
	print '<img style="display:none;" id="' . $gallery_image_id . '" class="' . $gallery_image_class .  '"' . drupal_attributes($attributes) . ' />';

}
//$attributes['width'] = 620;
//$attributes['height'] = $value['image_dimensions']['height'];

 
               
		?>
              </a>
            </div>
            <div id="main-image-caption-<?php print $key; ?>" class="image-caption clearfix"><div align="center"><?php print $image_number . '/' . $total_image_count; ?></div><div align="center"><?php print $image_description; ?></div></div>
          </div>
          <?php  $image_number++;?>
          <?php endforeach; ?>
	</div>
	<?php if((count($arrImages)) > 1) : ?>
        <div id="gallery-navigation" class="gallery-navigation">
          <div class="float-left previous">&nbsp;</div>
          <div class="float-right next">&nbsp;</div>
        </div>
	<?php endif; ?>
      </div>
    </div>
  </div>
</div>

<script type='text/javascript'>

var googletag = googletag || {};

googletag.cmd = googletag.cmd || [];

(function() {

var gads = document.createElement('script');

gads.async = true;

gads.type = 'text/javascript';

var useSSL = 'https:' == document.location.protocol;

gads.src = (useSSL ? 'https:' : 'http:') +

'//www.googletagservices.com/tag/js/gpt.js';

var node = document.getElementsByTagName('script')[0];

node.parentNode.insertBefore(gads, node);

})();

</script><script type='text/javascript'>
  var counter = 1; var slot1; var slot2; var slot3;

googletag.cmd.push(function() {
  //slot2 = googletag.defineSlot('/1754161/gam-holder-DC_AllPages_Rightside_300x250', [300, 250], 'gam-holder-DC_AllPages_Rightside_300x250').addService(googletag.pubads());
  slot1 = googletag.defineSlot('/1754161/gam-holder-DC_Gallerypages_Top_Leaderboard_728x90', [728, 90], 'gam-holder-DC_Gallerypages_Top_Leaderboard_728x90').addService(googletag.pubads());
  slot2 = googletag.defineSlot('/1754161/gam-holder-DC_Gallerypages_Middle_Leaderboard_728x90', [728, 90], 'gam-holder-DC_Gallerypages_Middle_Leaderboard_728x90').addService(googletag.pubads());
  slot3 = googletag.defineSlot('/1754161/gam-holder-DC_Gallerypages_Top_Rectangle_300x250', [300, 250], 'gam-holder-DC_Gallerypages_Top_Rectangle_300x250').addService(googletag.pubads());  

googletag.pubads().enableSingleRequest();

googletag.enableServices();

});

function refreshTag(){
 
  if(document.getElementById('block-google-admanager-154f67a970e303fbfd54a7374f8e08f8') != null) {
    var slot1_height = document.getElementById('block-google-admanager-37d27b61b0ecffb13da72c430d8e12fc').offsetHeight; //get the height of ads 
    var slot2_height = document.getElementById('block-google-admanager-154f67a970e303fbfd54a7374f8e08f8').offsetHeight;
    var slot3_height = document.getElementById('block-google-admanager-26b0a268a5ad63c8745cc74d104cf1e2').offsetHeight;
    
    // Check for ad blocker
    if(slot1_height !=  0 && slot2_height != 0 && slot3_height != 0) {
      googletag.pubads().refresh([slot1, slot2, slot3]);
    }
  }
}

</script>